<template>
	<view>
		<view class="text-center margin-top-xl padding-tb">
			<uv-count-down :time="15 * 60 * 60 * 1000" format="HH:mm:ss"></uv-count-down>
			<view class="text-black text-xxl text-bold padding-sm">
				800
			</view>
			<view class="">
				订单编号：3333
			</view>
		</view>
		<view class="bg-white margin radius-lg">
			<uv-cell icon="weixin-circle-fill" title="微信支付" :iconStyle="{color: '#0BCA89'}">
				<template v-slot:value>
					<uv-radio-group value="1" :customStyle="{'justify-content': 'flex-end'}">
						<uv-radio name="1" activeColor="#0BCA89" :checked="true"></uv-radio>
					</uv-radio-group>
				</template>
			</uv-cell>
		</view>
		<view class="foot-box">

			<button class="cu-btn bg-green flex-sub" @click="submit">确认支付</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: ''
			}
		},
		onLoad(opt) {
			this.id = opt.id
			this.loadOrderInfo()
		},
		methods: {
			loadOrderInfo() {
				const pl = {
					"orderId": "1935991796427366402", // 订单id
					"amount": 0.1,
					"openId": "o3teo7Xv5JSlbXTloJodMobUUTOw", // openId
					"description": "测试订单" // 订单名称
				}
				this.$http.post(`/cadre/highSeasOrder/create`, pl).then(res => {
					console.log(res)
				})
			},
			submit() {
				//订单对象，从服务器获取
				var orderInfo = {
					"appid": "wx499********7c70e", // 应用ID（AppID）
					"partnerid": "148*****52", // 商户号（PartnerID）
					"prepayid": "wx202254********************fbe90000", // 预支付交易会话ID
					"package": "Sign=WXPay", // 固定值
					"noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串
					"timestamp": 1597935292, // 时间戳（单位：秒）
					"sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名，这里用的 MD5 签名
				};
				uni.getProvider({
					service: 'payment',
					success: function(res) {
						console.log(res.provider)
						if (res.provider.indexOf('wxpay')) {
							uni.requestPayment({
								"provider": "wxpay", //固定值为"wxpay"
								"orderInfo": orderInfo,
								success: function(res) {
									var rawdata = JSON.parse(res.rawdata);
									console.log("支付成功");
								},
								fail: function(err) {
									console.log('支付失败:' + JSON.stringify(err));
								}
							});
						}
					}
				});
			}
		}
	}
</script>

<style scoped>
	.foot-box {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		background-color: #fff;
	}
</style>